package com.techindata.cacheredis;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Properties;

import org.apache.log4j.Logger;

import com.google.common.io.Resources;

/**
 * @author jixiang
 * 
 *         cache的初始化配置
 * */
public class CacheInit {
	static Logger logger = Logger
			.getLogger(CacheInit.class.getName());
	static String REDIS_CONFIG_NAME_FILE = "redis.properties"; 
	static String REDIS_IP;
	static String REDIS_PASSWD = "";
	static String REDIS_TIMEOUT = "";
	static int REDIS_PORT;
	static int EXPIRE=8*60*60;
	//public static int REDIS_CACHE_PORT_INIT = 6379;
	// cache的连接信息
	static {
		try {
			/*URL url = CacheInit.class.getResource(REDIS_CONFIG_NAME_FILE);
			Properties prop = new Properties();
			InputStream is = url.openStream();
		    prop.load(is);*/
			
		    Properties prop = new Properties();
			ClassLoader classLoader = CacheInit.class.getClassLoader();// 读取属性文件xxxxx.properties
			InputStream in = classLoader.getResourceAsStream(REDIS_CONFIG_NAME_FILE);
			prop.load(in); /// 加载属性列表
			/*InputStream inputStream = CacheInit.class.getClassLoader().getResourceAsStream(REDIS_CONFIG_NAME_FILE);
			Properties prop = new Properties();
			prop.load(inputStream);
		*/
			REDIS_IP = prop.getProperty("redis.ip".trim());
			REDIS_PASSWD = prop.getProperty("redis.passwd".trim());
			REDIS_TIMEOUT = prop.getProperty("redis.timeout".trim());
			REDIS_PORT=Integer.valueOf(prop.getProperty("redis.port".trim()));
		} catch (IOException e) {
			logger.error(e.getMessage(), e);
		}

	}

}
